<template>
  <div class="goods-hot">
    <h3>{{ TYPES[type] }}</h3>
    <!-- 商品区块 -->
    <RouterLink to="/" class="goods-item" v-for="good in hotData" :key="good.id">
      <img :src="good.picture" alt="" />
      <p class="name ellipsis">商品标题</p>
      <p class="desc ellipsis">商品描述</p>
      <p class="price">&yen;120.00</p>
    </RouterLink>
  </div>
</template>
<script>
// 1. 标题不一样      2. 列表数据不一样
// 第一步: 静态数据 -> 接口数据渲染出来
// 第二步: 适配

// 关键点: -> type 组件复用的时候可以有不同的type值就可以解决这个问题
import { findHotGoods } from '@/api/good.js'
import { useRoute } from 'vue-router'
import { ref } from 'vue'
export default {
  name: 'GoodsHot',
  props: {
    type: {
      type: Number
    }
  },
  setup (props) {
    const TYPES = {
      1: '24小时热榜',
      2: '周热榜'
    }
    const route = useRoute()
    const hotData = ref([])
    async function loadData () {
      const res = await findHotGoods({
        id: route.params.id,
        type: props.type
      })
      hotData.value = res.data.result
    }
    loadData()
    return {
      hotData,
      TYPES
    }
  }
}
</script>
<style scoped lang="less">
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
  .goods-item {
    display: block;
    padding: 20px 30px;
    text-align: center;
    background: #fff;
    img {
      width: 160px;
      height: 160px;
    }
    p {
      padding-top: 10px;
    }
    .name {
      font-size: 16px;
    }
    .desc {
      color: #999;
      height: 29px;
    }
    .price {
      color: @priceColor;
      font-size: 20px;
    }
  }
}
</style>
